﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class IntransitDetailDA : IIntransitDetailDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string INTRANSIT_ID = "@INTRANSIT_ID";
        private string LINE_ID = "@LINE_ID";
        private string ORDER_LINE_ID = "@ORDER_LINE_ID";
        private string OWNER_ID = "@OWNER_ID";
        private string PACK_ID = "@PACK_ID";
        private string QTY = "@QTY";
        private string RECEIPT_LINE_ID = "@RECEIPT_LINE_ID";
        private string RECEIVED_QTY = "@RECEIVED_QTY";
        private string REMARK = "@REMARK";
        private string SHIPPED_QTY = "@SHIPPED_QTY";
        private string SKU_ID = "@SKU_ID";
        private string SQL_CHECK_INTRANSIT_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@INTRANSIT_DETAIL WHERE INTRANSIT_ID = @INTRANSIT_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_INTRANSIT_DETAIL = " DELETE FROM @_@INTRANSIT_DETAIL WHERE INTRANSIT_ID = @INTRANSIT_ID  ";
        private string SQL_DELETE_INTRANSIT_DETAIL_BY_ORDER_ID = " DELETE ID FROM @_@INTRANSIT I ,@_@INTRANSIT_DETAIL ID WHERE I.INTRANSIT_ID = ID.INTRANSIT_ID AND I.ORDER_ID = @ORDER_ID ";
        private string SQL_DELETE_INTRANSIT_DETAIL_BY_ORDER_ID_AND_LINE_ID = "  DELETE ID FROM @_@INTRANSIT I ,@_@INTRANSIT_DETAIL ID WHERE I.INTRANSIT_ID = ID.INTRANSIT_ID AND ORDER_ID = @ORDER_ID AND ORDER_LINE_ID = @ORDER_LINE_ID ";
        private string SQL_INSERT_INTRANSIT_DETAIL = " INSERT INTO @_@INTRANSIT_DETAIL ( WH_ID, INTRANSIT_ID, LINE_ID, ORDER_LINE_ID, RECEIPT_LINE_ID, OWNER_ID, SKU_ID, UOM_ID, PACK_ID, QTY, SHIPPED_QTY, RECEIVED_QTY, STATUS, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @INTRANSIT_ID, @LINE_ID, @ORDER_LINE_ID, @RECEIPT_LINE_ID, @OWNER_ID, @SKU_ID, @UOM_ID, @PACK_ID, @QTY, @SHIPPED_QTY, @RECEIVED_QTY, @STATUS, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @UDF6, @UDF7, @UDF8, @UDF9, @UDF10, @REMARK, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_INTRANSIT_DETAIL = "SELECT DISTINCT INTRANSITDETAL.*,SKU.DESCR AS SKU_DESCR,UOM.UOM_DESCR, ORDERDETAIL.LOT_ATTR01, ORDERDETAIL.LOT_ATTR02,  ORDERDETAIL.LOT_ATTR03, ORDERDETAIL.LOT_ATTR04, ORDERDETAIL.LOT_ATTR05, ORDERDETAIL.LOT_ATTR06,  ORDERDETAIL.LOT_ATTR07, ORDERDETAIL.LOT_ATTR08,ORDERDETAIL.LOT_ATTR09, ORDERDETAIL.LOT_ATTR10, ORDERDETAIL.PRODUCE_DATE,  ORDERDETAIL.EXPIRY_DATE, ORDERDETAIL.EXTERNAL_LOT  FROM         @_@INTRANSIT_DETAIL INTRANSITDETAL INNER JOIN  @_@ORDER_DETAIL ORDERDETAIL ON INTRANSITDETAL.ORDER_LINE_ID = ORDERDETAIL.LINE_ID INNER JOIN  @_@INTRANSIT INTRANSIT ON INTRANSITDETAL.INTRANSIT_ID = INTRANSIT.INTRANSIT_ID AND   ORDERDETAIL.ORDER_ID = INTRANSIT.ORDER_ID  LEFT JOIN @_@SKU SKU ON INTRANSITDETAL.SKU_ID = SKU.SKU_ID AND INTRANSITDETAL.OWNER_ID = SKU.OWNER_ID LEFT JOIN @_@UOM UOM ON INTRANSITDETAL.UOM_ID = UOM.UOM_ID ";
        private string SQL_SELECT_INTRANSIT_DETAIL_BY_ORDER_ID = " SELECT DISTINCT ID.*,SKU.DESCR AS SKU_DESCR,UOM.UOM_DESCR FROM @_@INTRANSIT_DETAIL ID  LEFT JOIN @_@INTRANSIT I ON ID.INTRANSIT_ID = I.INTRANSIT_ID  LEFT JOIN @_@SKU SKU ON ID.SKU_ID = SKU.SKU_ID LEFT JOIN @_@UOM UOM ON ID.UOM_ID = UOM.UOM_ID  WHERE I.ORDER_ID = @ORDER_ID AND ID.ORDER_LINE_ID = @ORDER_LINE_ID ";
        private string SQL_UPDATE_INTRANSIT_DETAIL = " UPDATE @_@INTRANSIT_DETAIL SET WH_ID = @WH_ID, ORDER_LINE_ID = @ORDER_LINE_ID, RECEIPT_LINE_ID = @RECEIPT_LINE_ID, OWNER_ID = @OWNER_ID, SKU_ID = @SKU_ID, UOM_ID = @UOM_ID, PACK_ID = @PACK_ID, QTY = @QTY, SHIPPED_QTY = @SHIPPED_QTY, RECEIVED_QTY = @RECEIVED_QTY, STATUS = @STATUS, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UDF6 = @UDF6, UDF7 = @UDF7, UDF8 = @UDF8, UDF9 = @UDF9, UDF10 = @UDF10, REMARK = @REMARK, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE INTRANSIT_ID = @INTRANSIT_ID AND LINE_ID = @LINE_ID  ";
        private string SQL_UPDATE_INTRANSIT_DETAIL_RECEIVED_QTY_AND_STATUS = " UPDATE ID SET RECEIVED_QTY = RECEIVED_QTY + @RECEIVED_QTY,STATUS = @STATUS,UPDATED_BY = @UPDATED_BY,UPDATED_DATE = GETDATE() FROM @_@INTRANSIT_DETAIL ID LEFT JOIN @_@INTRANSIT I ON ID.INTRANSIT_ID = I.INTRANSIT_ID WHERE ID.ORDER_LINE_ID = @ORDER_LINE_ID AND I.ORDER_ID = @ORDER_ID ";
        private string SQL_UPDATE_INTRANSIT_DETAIL_SHIPPED_QTY_AND_STATUS = " UPDATE ID SET SHIPPED_QTY = SHIPPED_QTY + @SHIPPED_QTY,STATUS = @STATUS,UPDATED_BY = @UPDATED_BY,UPDATED_DATE = GETDATE() FROM @_@INTRANSIT_DETAIL ID LEFT JOIN @_@INTRANSIT I ON ID.INTRANSIT_ID = I.INTRANSIT_ID WHERE ID.ORDER_LINE_ID = @ORDER_LINE_ID AND I.ORDER_ID = @ORDER_ID ";
        private string STATUS = "@STATUS";
        private string TS = "@TS";
        private string UDF1 = "@UDF1";
        private string UDF10 = "@UDF10";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UDF6 = "@UDF6";
        private string UDF7 = "@UDF7";
        private string UDF8 = "@UDF8";
        private string UDF9 = "@UDF9";
        private string UOM_ID = "@UOM_ID";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckIntransitDetailIDUnique(string intransitDetailID, string lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitDetailID), new SqlParameter("@LINE_ID", lineID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_INTRANSIT_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckIntransitDetailIDUnique(DataBase dataBase, DbTransaction tran, string intransitDetailID, string lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitDetailID), new SqlParameter("@LINE_ID", lineID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_INTRANSIT_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteIntransitDetail(List<string> intransitIDs, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < intransitIDs.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitIDs[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INTRANSIT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteIntransitDetail(List<string> intransitDetailIDs, List<string> LineIDs, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string sql = this.SQL_DELETE_INTRANSIT_DETAIL + " AND LINE_ID = @LINE_ID";
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < intransitDetailIDs.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitDetailIDs[j]), new SqlParameter("@LINE_ID", LineIDs[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sql.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteIntransitDetail(DataBase dataBase, DbTransaction tran, List<string> intransitIDs, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < intransitIDs.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitIDs[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INTRANSIT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int DeleteIntransitDetail(DataBase dataBase, DbTransaction tran, List<string> intransitDetailIDs, List<string> LineIDs, List<string> whLoginID)
        {
            int result = 0;
            string sql = this.SQL_DELETE_INTRANSIT_DETAIL + " AND LINE_ID = @LINE_ID";
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < intransitDetailIDs.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitDetailIDs[j]), new SqlParameter("@LINE_ID", LineIDs[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sql.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int DeleteIntransitDetailByOrderID(List<string> orderIDs, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int j = 0; j < orderIDs.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderIDs[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INTRANSIT_DETAIL_BY_ORDER_ID.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteIntransitDetailByOrderID(List<string> orderIDs, List<string> LineIDs, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < orderIDs.Count; i++)
                {
                    for (int j = 0; j < orderIDs.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderIDs[j]), new SqlParameter("@ORDER_LINE_ID", LineIDs[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INTRANSIT_DETAIL_BY_ORDER_ID_AND_LINE_ID.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteIntransitDetailByOrderID(DataBase dataBase, DbTransaction tran, List<string> orderIDs, string whLoginID)
        {
            int result = 0;
            try
            {
                for (int j = 0; j < orderIDs.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderIDs[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INTRANSIT_DETAIL_BY_ORDER_ID.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int DeleteIntransitDetailByOrderID(DataBase dataBase, DbTransaction tran, List<string> orderIDs, List<string> LineIDs, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < orderIDs.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderIDs[j]), new SqlParameter("@ORDER_LINE_ID", LineIDs[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INTRANSIT_DETAIL_BY_ORDER_ID_AND_LINE_ID.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllIntransitDetail(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INTRANSIT_DETAIL.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllIntransitDetail(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INTRANSIT_DETAIL.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public IntransitDetailInfo GetIntransitDetailByID(string intransitdetailID, string LineID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INTRANSIT_DETAIL.Replace("@_@", whLoginID) + " WHERE INTRANSITDETAL.INTRANSIT_ID = @INTRANSIT_ID AND INTRANSITDETAL.LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitdetailID), new SqlParameter("@LINE_ID", LineID) };
            IntransitDetailInfo intransitDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    DateTime CS00003;
                    intransitDetailInfo = new IntransitDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INTRANSIT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, (reader["RECEIPT_LINE_ID"].ToString() != "") ? int.Parse(reader["RECEIPT_LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["UOM_ID"].ToString(), reader["PACK_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, (reader["SHIPPED_QTY"].ToString() != "") ? decimal.Parse(reader["SHIPPED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["LOT_ATTR01"].ToString(), reader["LOT_ATTR02"].ToString(), reader["LOT_ATTR03"].ToString(), reader["LOT_ATTR04"].ToString(), reader["LOT_ATTR05"].ToString(), reader["LOT_ATTR06"].ToString(), reader["LOT_ATTR07"].ToString(), reader["LOT_ATTR08"].ToString(), reader["LOT_ATTR09"].ToString(), reader["LOT_ATTR10"].ToString(), (reader["PRODUCE_DATE"].ToString() != "") ? DateTime.Parse(reader["PRODUCE_DATE"].ToString()) : (CS00003 = new DateTime()), (reader["EXPIRY_DATE"].ToString() != "") ? DateTime.Parse(reader["EXPIRY_DATE"].ToString()) : new DateTime(), reader["EXTERNAL_LOT"].ToString(), reader["SKU_DESCR"].ToString(), reader["UOM_DESCR"].ToString());
                }
            }
            return intransitDetailInfo;
        }

        public IntransitDetailInfo GetIntransitDetailByID(DataBase dataBase, DbTransaction tran, string intransitdetailID, string LineID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INTRANSIT_DETAIL.Replace("@_@", whLoginID) + " WHERE INTRANSITDETAL.INTRANSIT_ID = @INTRANSIT_ID AND INTRANSITDETAL.LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitdetailID), new SqlParameter("@LINE_ID", LineID) };
            IntransitDetailInfo intransitDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                DateTime CS00003;
                intransitDetailInfo = new IntransitDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INTRANSIT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, (reader["RECEIPT_LINE_ID"].ToString() != "") ? int.Parse(reader["RECEIPT_LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["UOM_ID"].ToString(), reader["PACK_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, (reader["SHIPPED_QTY"].ToString() != "") ? decimal.Parse(reader["SHIPPED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["LOT_ATTR01"].ToString(), reader["LOT_ATTR02"].ToString(), reader["LOT_ATTR03"].ToString(), reader["LOT_ATTR04"].ToString(), reader["LOT_ATTR05"].ToString(), reader["LOT_ATTR06"].ToString(), reader["LOT_ATTR07"].ToString(), reader["LOT_ATTR08"].ToString(), reader["LOT_ATTR09"].ToString(), reader["LOT_ATTR10"].ToString(), (reader["PRODUCE_DATE"].ToString() != "") ? DateTime.Parse(reader["PRODUCE_DATE"].ToString()) : (CS00003 = new DateTime()), (reader["EXPIRY_DATE"].ToString() != "") ? DateTime.Parse(reader["EXPIRY_DATE"].ToString()) : new DateTime(), reader["EXTERNAL_LOT"].ToString(), reader["SKU_DESCR"].ToString(), reader["UOM_DESCR"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return intransitDetailInfo;
        }

        public IntransitDetailInfo GetIntransitDetailByOrderID(string orderID, string LineID, string whLoginID)
        {
            string sql = this.SQL_SELECT_INTRANSIT_DETAIL_BY_ORDER_ID.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderID), new SqlParameter("@ORDER_LINE_ID", LineID) };
            IntransitDetailInfo intransitDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    intransitDetailInfo = new IntransitDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INTRANSIT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, (reader["RECEIPT_LINE_ID"].ToString() != "") ? int.Parse(reader["RECEIPT_LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["UOM_ID"].ToString(), reader["PACK_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, (reader["SHIPPED_QTY"].ToString() != "") ? decimal.Parse(reader["SHIPPED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["SKU_DESCR"].ToString(), reader["UOM_DESCR"].ToString());
                }
            }
            return intransitDetailInfo;
        }

        public IntransitDetailInfo GetIntransitDetailByOrderID(DataBase dataBase, DbTransaction tran, string orderID, string LineID, string whLoginID)
        {
            string sql = this.SQL_SELECT_INTRANSIT_DETAIL_BY_ORDER_ID.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderID), new SqlParameter("@ORDER_LINE_ID", LineID) };
            IntransitDetailInfo intransitDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                intransitDetailInfo = new IntransitDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INTRANSIT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, (reader["RECEIPT_LINE_ID"].ToString() != "") ? int.Parse(reader["RECEIPT_LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["UOM_ID"].ToString(), reader["PACK_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, (reader["SHIPPED_QTY"].ToString() != "") ? decimal.Parse(reader["SHIPPED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["SKU_DESCR"].ToString(), reader["UOM_DESCR"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return intransitDetailInfo;
        }

        public DataSet GetIntransitDetailByQueryList(List<string> sqlWhere, IntransitDetailQueryEntity intransitdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_INTRANSIT_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!intransitdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, intransitdetailQuery.CurrentPage, intransitdetailQuery.PageSize, intransitdetailQuery.SortField, intransitdetailQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetIntransitDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, IntransitDetailQueryEntity intransitdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_INTRANSIT_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!intransitdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, intransitdetailQuery.CurrentPage, intransitdetailQuery.PageSize, intransitdetailQuery.SortField, intransitdetailQuery.SortDirection);
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public List<IntransitDetailInfo> GetIntransitDetailListByID(string intransitID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INTRANSIT_DETAIL + "WHERE INTRANSITDETAL.INTRANSIT_ID = @INTRANSIT_ID";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitID) };
            sql = sql.Replace("@_@", whLoginID);
            List<IntransitDetailInfo> IntransitDetailInfos = new List<IntransitDetailInfo>();
            IntransitDetailInfo intransitDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    intransitDetailInfo = new IntransitDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INTRANSIT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, (reader["RECEIPT_LINE_ID"].ToString() != "") ? int.Parse(reader["RECEIPT_LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["UOM_ID"].ToString(), reader["PACK_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, (reader["SHIPPED_QTY"].ToString() != "") ? decimal.Parse(reader["SHIPPED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["LOT_ATTR01"].ToString(), reader["LOT_ATTR02"].ToString(), reader["LOT_ATTR03"].ToString(), reader["LOT_ATTR04"].ToString(), reader["LOT_ATTR05"].ToString(), reader["LOT_ATTR06"].ToString(), reader["LOT_ATTR07"].ToString(), reader["LOT_ATTR08"].ToString(), reader["LOT_ATTR09"].ToString(), reader["LOT_ATTR10"].ToString(), (reader["PRODUCE_DATE"].ToString() != "") ? DateTime.Parse(reader["PRODUCE_DATE"].ToString()) : (CS00002 = new DateTime()), (reader["EXPIRY_DATE"].ToString() != "") ? DateTime.Parse(reader["EXPIRY_DATE"].ToString()) : (CS00002 = new DateTime()), reader["EXTERNAL_LOT"].ToString(), reader["SKU_DESCR"].ToString(), reader["UOM_DESCR"].ToString());
                    IntransitDetailInfos.Add(intransitDetailInfo);
                }
            }
            return IntransitDetailInfos;
        }

        public List<IntransitDetailInfo> GetIntransitDetailListByID(DataBase dataBase, DbTransaction tran, string intransitID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INTRANSIT_DETAIL + "WHERE INTRANSITDETAL.INTRANSIT_ID = @INTRANSIT_ID";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INTRANSIT_ID", intransitID) };
            sql = sql.Replace("@_@", whLoginID);
            List<IntransitDetailInfo> IntransitDetailInfos = new List<IntransitDetailInfo>();
            IntransitDetailInfo intransitDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            while (reader.Read())
            {
                DateTime CS00002;
                intransitDetailInfo = new IntransitDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INTRANSIT_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, (reader["RECEIPT_LINE_ID"].ToString() != "") ? int.Parse(reader["RECEIPT_LINE_ID"].ToString()) : 0, reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["UOM_ID"].ToString(), reader["PACK_ID"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, (reader["SHIPPED_QTY"].ToString() != "") ? decimal.Parse(reader["SHIPPED_QTY"].ToString()) : 0M, (reader["RECEIVED_QTY"].ToString() != "") ? decimal.Parse(reader["RECEIVED_QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["LOT_ATTR01"].ToString(), reader["LOT_ATTR02"].ToString(), reader["LOT_ATTR03"].ToString(), reader["LOT_ATTR04"].ToString(), reader["LOT_ATTR05"].ToString(), reader["LOT_ATTR06"].ToString(), reader["LOT_ATTR07"].ToString(), reader["LOT_ATTR08"].ToString(), reader["LOT_ATTR09"].ToString(), reader["LOT_ATTR10"].ToString(), (reader["PRODUCE_DATE"].ToString() != "") ? DateTime.Parse(reader["PRODUCE_DATE"].ToString()) : (CS00002 = new DateTime()), (reader["EXPIRY_DATE"].ToString() != "") ? DateTime.Parse(reader["EXPIRY_DATE"].ToString()) : (CS00002 = new DateTime()), reader["EXTERNAL_LOT"].ToString(), reader["SKU_DESCR"].ToString(), reader["UOM_DESCR"].ToString());
                IntransitDetailInfos.Add(intransitDetailInfo);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return IntransitDetailInfos;
        }

        public int InsertIntransitDetail(IntransitDetailInfo intransitDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    intransitDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_IntransitDetail_Parameters(intransitDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_INTRANSIT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertIntransitDetail(DataBase dataBase, DbTransaction tran, IntransitDetailInfo intransitDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    intransitDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_IntransitDetail_Parameters(intransitDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_INTRANSIT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_IntransitDetail_Parameters(IntransitDetailInfo intransitDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.INTRANSIT_ID, SqlDbType.VarChar, 20), new SqlParameter(this.LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.ORDER_LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.RECEIPT_LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.OWNER_ID, SqlDbType.VarChar, 20), new SqlParameter(this.SKU_ID, SqlDbType.VarChar, 50), new SqlParameter(this.UOM_ID, SqlDbType.VarChar, 20), new SqlParameter(this.PACK_ID, SqlDbType.VarChar, 50), new SqlParameter(this.QTY, SqlDbType.Decimal, 13), new SqlParameter(this.SHIPPED_QTY, SqlDbType.Decimal, 13), new SqlParameter(this.RECEIVED_QTY, SqlDbType.Decimal, 13), new SqlParameter(this.STATUS, SqlDbType.VarChar, 20), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), 
                new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.UDF6, SqlDbType.VarChar, 30), new SqlParameter(this.UDF7, SqlDbType.VarChar, 30), new SqlParameter(this.UDF8, SqlDbType.VarChar, 30), new SqlParameter(this.UDF9, SqlDbType.VarChar, 30), new SqlParameter(this.UDF10, SqlDbType.VarChar, 30), new SqlParameter(this.REMARK, SqlDbType.VarChar, 0x200), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20)
             };
            if (!string.IsNullOrEmpty(intransitDetailInfo.WhID))
            {
                paramArray[0].Value = intransitDetailInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = intransitDetailInfo.IntransitID;
            paramArray[2].Value = intransitDetailInfo.LineID;
            paramArray[3].Value = intransitDetailInfo.OrderLineID;
            paramArray[4].Value = intransitDetailInfo.ReceiptLineID;
            paramArray[5].Value = intransitDetailInfo.OwnerID;
            paramArray[6].Value = intransitDetailInfo.SkuID;
            paramArray[7].Value = intransitDetailInfo.UomID;
            paramArray[8].Value = intransitDetailInfo.PackID;
            paramArray[9].Value = intransitDetailInfo.Qty;
            paramArray[10].Value = intransitDetailInfo.ShippedQty;
            paramArray[11].Value = intransitDetailInfo.ReceivedQty;
            paramArray[12].Value = intransitDetailInfo.Status;
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf1))
            {
                paramArray[13].Value = intransitDetailInfo.Udf1;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf2))
            {
                paramArray[14].Value = intransitDetailInfo.Udf2;
            }
            else
            {
                paramArray[14].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf3))
            {
                paramArray[15].Value = intransitDetailInfo.Udf3;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf4))
            {
                paramArray[0x10].Value = intransitDetailInfo.Udf4;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf5))
            {
                paramArray[0x11].Value = intransitDetailInfo.Udf5;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf6))
            {
                paramArray[0x12].Value = intransitDetailInfo.Udf6;
            }
            else
            {
                paramArray[0x12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf7))
            {
                paramArray[0x13].Value = intransitDetailInfo.Udf7;
            }
            else
            {
                paramArray[0x13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf8))
            {
                paramArray[20].Value = intransitDetailInfo.Udf8;
            }
            else
            {
                paramArray[20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf9))
            {
                paramArray[0x15].Value = intransitDetailInfo.Udf9;
            }
            else
            {
                paramArray[0x15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Udf10))
            {
                paramArray[0x16].Value = intransitDetailInfo.Udf10;
            }
            else
            {
                paramArray[0x16].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(intransitDetailInfo.Remark))
            {
                paramArray[0x17].Value = intransitDetailInfo.Remark;
            }
            else
            {
                paramArray[0x17].Value = DBNull.Value;
            }
            paramArray[0x18].Value = intransitDetailInfo.CreatedBy;
            paramArray[0x19].Value = intransitDetailInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateIntransitDetail(IntransitDetailInfo intransitDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    intransitDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_IntransitDetail_Parameters(intransitDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_INTRANSIT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateIntransitDetail(DataBase dataBase, DbTransaction tran, IntransitDetailInfo intransitDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    intransitDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_IntransitDetail_Parameters(intransitDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_INTRANSIT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateIntransitDetailQty(string orderID, string orderLineID, string updateType, decimal qty, string status, string updatedBy, string whLoginID)
        {
            int result = 0;
            try
            {
                string sql = string.Empty;
                SqlParameter[] paras = null;
                string CS40001 = updateType;
                if (CS40001 != null)
                {
                    if (!(CS40001 == "ShippedQty"))
                    {
                        if (CS40001 == "ReceivedQty")
                        {
                            goto Label_00AA;
                        }
                    }
                    else
                    {
                        sql = this.SQL_UPDATE_INTRANSIT_DETAIL_SHIPPED_QTY_AND_STATUS.Replace("@_@", whLoginID);
                        paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderID), new SqlParameter("@ORDER_LINE_ID", orderLineID), new SqlParameter("@SHIPPED_QTY", qty), new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", updatedBy) };
                    }
                }
                goto Label_011D;
            Label_00AA:
                sql = this.SQL_UPDATE_INTRANSIT_DETAIL_RECEIVED_QTY_AND_STATUS.Replace("@_@", whLoginID);
                paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderID), new SqlParameter("@ORDER_LINE_ID", orderLineID), new SqlParameter("@RECEIVED_QTY", qty), new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", updatedBy) };
            Label_011D:
                if (paras != null)
                {
                    result += DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateIntransitDetailQty(DataBase dataBase, DbTransaction tran, string orderID, string orderLineID, string updateType, decimal qty, string status, string updatedBy, string whLoginID)
        {
            int result = 0;
            try
            {
                string sql = string.Empty;
                SqlParameter[] paras = null;
                string CS40001 = updateType;
                if (CS40001 != null)
                {
                    if (!(CS40001 == "ShippedQty"))
                    {
                        if (CS40001 == "ReceivedQty")
                        {
                            goto Label_00AC;
                        }
                    }
                    else
                    {
                        sql = this.SQL_UPDATE_INTRANSIT_DETAIL_SHIPPED_QTY_AND_STATUS.Replace("@_@", whLoginID);
                        paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderID), new SqlParameter("@ORDER_LINE_ID", orderLineID), new SqlParameter("@SHIPPED_QTY", qty), new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", updatedBy) };
                    }
                }
                goto Label_0120;
            Label_00AC:
                sql = this.SQL_UPDATE_INTRANSIT_DETAIL_RECEIVED_QTY_AND_STATUS.Replace("@_@", whLoginID);
                paras = new SqlParameter[] { new SqlParameter("@ORDER_ID", orderID), new SqlParameter("@ORDER_LINE_ID", orderLineID), new SqlParameter("@RECEIVED_QTY", qty), new SqlParameter("@STATUS", status), new SqlParameter("@UPDATED_BY", updatedBy) };
            Label_0120:
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sql, paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

